{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 共享单车使用数量预测-线性回归\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1、导入工具包"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np #矩阵操作\n",
    "import pandas as pd # SQL数据处理\n",
    "\n",
    "from sklearn.metrics import r2_score \n",
    "\n",
    "import matplotlib.pyplot as plt \n",
    "import seaborn as sns\n",
    "\n",
    "#图形出现在notebook里而不是新窗口\n",
    "%matplotlib inline\n",
    "#魔法命令\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2、数据探索"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.1读取数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>instant</th>\n",
       "      <th>dteday</th>\n",
       "      <th>season</th>\n",
       "      <th>yr</th>\n",
       "      <th>mnth</th>\n",
       "      <th>holiday</th>\n",
       "      <th>weekday</th>\n",
       "      <th>workingday</th>\n",
       "      <th>weathersit</th>\n",
       "      <th>temp</th>\n",
       "      <th>atemp</th>\n",
       "      <th>hum</th>\n",
       "      <th>windspeed</th>\n",
       "      <th>casual</th>\n",
       "      <th>registered</th>\n",
       "      <th>cnt</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>2011-01-01</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0.344167</td>\n",
       "      <td>0.363625</td>\n",
       "      <td>0.805833</td>\n",
       "      <td>0.160446</td>\n",
       "      <td>331</td>\n",
       "      <td>654</td>\n",
       "      <td>985</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>2011-01-02</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0.363478</td>\n",
       "      <td>0.353739</td>\n",
       "      <td>0.696087</td>\n",
       "      <td>0.248539</td>\n",
       "      <td>131</td>\n",
       "      <td>670</td>\n",
       "      <td>801</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>2011-01-03</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0.196364</td>\n",
       "      <td>0.189405</td>\n",
       "      <td>0.437273</td>\n",
       "      <td>0.248309</td>\n",
       "      <td>120</td>\n",
       "      <td>1229</td>\n",
       "      <td>1349</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>2011-01-04</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0.200000</td>\n",
       "      <td>0.212122</td>\n",
       "      <td>0.590435</td>\n",
       "      <td>0.160296</td>\n",
       "      <td>108</td>\n",
       "      <td>1454</td>\n",
       "      <td>1562</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>2011-01-05</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0.226957</td>\n",
       "      <td>0.229270</td>\n",
       "      <td>0.436957</td>\n",
       "      <td>0.186900</td>\n",
       "      <td>82</td>\n",
       "      <td>1518</td>\n",
       "      <td>1600</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   instant      dteday  season  yr  mnth  holiday  weekday  workingday  \\\n",
       "0        1  2011-01-01       1   0     1        0        6           0   \n",
       "1        2  2011-01-02       1   0     1        0        0           0   \n",
       "2        3  2011-01-03       1   0     1        0        1           1   \n",
       "3        4  2011-01-04       1   0     1        0        2           1   \n",
       "4        5  2011-01-05       1   0     1        0        3           1   \n",
       "\n",
       "   weathersit      temp     atemp       hum  windspeed  casual  registered  \\\n",
       "0           2  0.344167  0.363625  0.805833   0.160446     331         654   \n",
       "1           2  0.363478  0.353739  0.696087   0.248539     131         670   \n",
       "2           1  0.196364  0.189405  0.437273   0.248309     120        1229   \n",
       "3           1  0.200000  0.212122  0.590435   0.160296     108        1454   \n",
       "4           1  0.226957  0.229270  0.436957   0.186900      82        1518   \n",
       "\n",
       "    cnt  \n",
       "0   985  \n",
       "1   801  \n",
       "2  1349  \n",
       "3  1562  \n",
       "4  1600  "
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = pd.read_csv(\"C:/Users/dell/Desktop/ai/one-week/homework/homework/day.csv\")\n",
    "#数据读取文件路径可以是相对路径和绝对路径加文件名\n",
    "data.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.2数据基本信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(731, 16)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 731 entries, 0 to 730\n",
      "Data columns (total 16 columns):\n",
      "instant       731 non-null int64\n",
      "dteday        731 non-null object\n",
      "season        731 non-null int64\n",
      "yr            731 non-null int64\n",
      "mnth          731 non-null int64\n",
      "holiday       731 non-null int64\n",
      "weekday       731 non-null int64\n",
      "workingday    731 non-null int64\n",
      "weathersit    731 non-null int64\n",
      "temp          731 non-null float64\n",
      "atemp         731 non-null float64\n",
      "hum           731 non-null float64\n",
      "windspeed     731 non-null float64\n",
      "casual        731 non-null int64\n",
      "registered    731 non-null int64\n",
      "cnt           731 non-null int64\n",
      "dtypes: float64(4), int64(11), object(1)\n",
      "memory usage: 91.5+ KB\n"
     ]
    }
   ],
   "source": [
    "data.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>instant</th>\n",
       "      <th>season</th>\n",
       "      <th>yr</th>\n",
       "      <th>mnth</th>\n",
       "      <th>holiday</th>\n",
       "      <th>weekday</th>\n",
       "      <th>workingday</th>\n",
       "      <th>weathersit</th>\n",
       "      <th>temp</th>\n",
       "      <th>atemp</th>\n",
       "      <th>hum</th>\n",
       "      <th>windspeed</th>\n",
       "      <th>casual</th>\n",
       "      <th>registered</th>\n",
       "      <th>cnt</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>731.000000</td>\n",
       "      <td>731.000000</td>\n",
       "      <td>731.000000</td>\n",
       "      <td>731.000000</td>\n",
       "      <td>731.000000</td>\n",
       "      <td>731.000000</td>\n",
       "      <td>731.000000</td>\n",
       "      <td>731.000000</td>\n",
       "      <td>731.000000</td>\n",
       "      <td>731.000000</td>\n",
       "      <td>731.000000</td>\n",
       "      <td>731.000000</td>\n",
       "      <td>731.000000</td>\n",
       "      <td>731.000000</td>\n",
       "      <td>731.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>366.000000</td>\n",
       "      <td>2.496580</td>\n",
       "      <td>0.500684</td>\n",
       "      <td>6.519836</td>\n",
       "      <td>0.028728</td>\n",
       "      <td>2.997264</td>\n",
       "      <td>0.683995</td>\n",
       "      <td>1.395349</td>\n",
       "      <td>0.495385</td>\n",
       "      <td>0.474354</td>\n",
       "      <td>0.627894</td>\n",
       "      <td>0.190486</td>\n",
       "      <td>848.176471</td>\n",
       "      <td>3656.172367</td>\n",
       "      <td>4504.348837</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>211.165812</td>\n",
       "      <td>1.110807</td>\n",
       "      <td>0.500342</td>\n",
       "      <td>3.451913</td>\n",
       "      <td>0.167155</td>\n",
       "      <td>2.004787</td>\n",
       "      <td>0.465233</td>\n",
       "      <td>0.544894</td>\n",
       "      <td>0.183051</td>\n",
       "      <td>0.162961</td>\n",
       "      <td>0.142429</td>\n",
       "      <td>0.077498</td>\n",
       "      <td>686.622488</td>\n",
       "      <td>1560.256377</td>\n",
       "      <td>1937.211452</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.059130</td>\n",
       "      <td>0.079070</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.022392</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>20.000000</td>\n",
       "      <td>22.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>183.500000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>4.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.337083</td>\n",
       "      <td>0.337842</td>\n",
       "      <td>0.520000</td>\n",
       "      <td>0.134950</td>\n",
       "      <td>315.500000</td>\n",
       "      <td>2497.000000</td>\n",
       "      <td>3152.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>366.000000</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>7.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.498333</td>\n",
       "      <td>0.486733</td>\n",
       "      <td>0.626667</td>\n",
       "      <td>0.180975</td>\n",
       "      <td>713.000000</td>\n",
       "      <td>3662.000000</td>\n",
       "      <td>4548.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>548.500000</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>10.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>0.655417</td>\n",
       "      <td>0.608602</td>\n",
       "      <td>0.730209</td>\n",
       "      <td>0.233214</td>\n",
       "      <td>1096.000000</td>\n",
       "      <td>4776.500000</td>\n",
       "      <td>5956.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>731.000000</td>\n",
       "      <td>4.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>12.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>6.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>0.861667</td>\n",
       "      <td>0.840896</td>\n",
       "      <td>0.972500</td>\n",
       "      <td>0.507463</td>\n",
       "      <td>3410.000000</td>\n",
       "      <td>6946.000000</td>\n",
       "      <td>8714.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          instant      season          yr        mnth     holiday     weekday  \\\n",
       "count  731.000000  731.000000  731.000000  731.000000  731.000000  731.000000   \n",
       "mean   366.000000    2.496580    0.500684    6.519836    0.028728    2.997264   \n",
       "std    211.165812    1.110807    0.500342    3.451913    0.167155    2.004787   \n",
       "min      1.000000    1.000000    0.000000    1.000000    0.000000    0.000000   \n",
       "25%    183.500000    2.000000    0.000000    4.000000    0.000000    1.000000   \n",
       "50%    366.000000    3.000000    1.000000    7.000000    0.000000    3.000000   \n",
       "75%    548.500000    3.000000    1.000000   10.000000    0.000000    5.000000   \n",
       "max    731.000000    4.000000    1.000000   12.000000    1.000000    6.000000   \n",
       "\n",
       "       workingday  weathersit        temp       atemp         hum   windspeed  \\\n",
       "count  731.000000  731.000000  731.000000  731.000000  731.000000  731.000000   \n",
       "mean     0.683995    1.395349    0.495385    0.474354    0.627894    0.190486   \n",
       "std      0.465233    0.544894    0.183051    0.162961    0.142429    0.077498   \n",
       "min      0.000000    1.000000    0.059130    0.079070    0.000000    0.022392   \n",
       "25%      0.000000    1.000000    0.337083    0.337842    0.520000    0.134950   \n",
       "50%      1.000000    1.000000    0.498333    0.486733    0.626667    0.180975   \n",
       "75%      1.000000    2.000000    0.655417    0.608602    0.730209    0.233214   \n",
       "max      1.000000    3.000000    0.861667    0.840896    0.972500    0.507463   \n",
       "\n",
       "            casual   registered          cnt  \n",
       "count   731.000000   731.000000   731.000000  \n",
       "mean    848.176471  3656.172367  4504.348837  \n",
       "std     686.622488  1560.256377  1937.211452  \n",
       "min       2.000000    20.000000    22.000000  \n",
       "25%     315.500000  2497.000000  3152.000000  \n",
       "50%     713.000000  3662.000000  4548.000000  \n",
       "75%    1096.000000  4776.500000  5956.000000  \n",
       "max    3410.000000  6946.000000  8714.000000  "
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.describe()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.3数据探索具体请见 bike-sharing.ipynb"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.4数据准备"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "#分离特征X 及输出 y\n",
    "#del data['instant']\n",
    "#y = data['cnt'].values\n",
    "#X = data.drop('cnt',axis = 1)\n",
    "#axis = 1 指删除列，drop 函数默认是指删除行\n",
    "#X.drop('instant',axis = 1,inplace = True)\n",
    "#X.drop('temp',axis = 1,inplace = True)\n",
    "#columns = X.columns\n",
    "#X.shape\n",
    "#此步放在分离测试数据及训练数据之后做"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 将数据分为训练数据及测试数据"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# from sklearn.model_selection import train_test_split\n",
    "#例子中train_test_split 采用的为 交叉验证\n",
    "#train_test_split(train_data,train_target,test_size=0.4, random_state=0)\n",
    "#其中：train_data为样本特征集，train_target 为样本结果，test_size 为测试样本所占比例，\n",
    "#如果为整数即测试样本数量，random_state 为随机数种子\n",
    "\n",
    "\n",
    "#作业要求采用2012年数据作为测试数据，这里不采用 train_test_split \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 124,
   "metadata": {},
   "outputs": [],
   "source": [
    "#对类别特征进行one-hot encoding 处理\n",
    "#需要剔除一些特征后，还剩下的类别特征有 季节、节假日、星期几、工作日\n",
    "from sklearn import preprocessing\n",
    "enc = preprocessing.OneHotEncoder()\n",
    "yy=enc.fit_transform(data.iloc[:,[2,5,6,7]].values).toarray()\n",
    "data_onehot=pd.DataFrame({\"season1\":yy[:,0],\"season2\":yy[:,1],\"season3\":yy[:,2],\"season4\":yy[:,3],\"holiday1\":yy[:,4],\"holiday2\":yy[:,5],\"weekday1\":yy[:,6],\"weekday2\":yy[:,7],\"weekday3\":yy[:,8],\"weekday4\":yy[:,9],\"weekday5\":yy[:,10],\"weekday6\":yy[:,11],\"weekday7\":yy[:,12],\"workingday1\":yy[:,13],\"workingday2\":yy[:,14]})\n",
    "data_new = pd.DataFrame.join(data,data_onehot,how='left',on=None)\n",
    "\n",
    "\n",
    "#分离测试数据及训练数据\n",
    "data_train = data_new[data_new.dteday<='2011/12/31']\n",
    "#删除无关列\n",
    "data_train = data_train.drop(['instant','dteday','season','mnth','yr','holiday','weekday','workingday','temp','casual','registered'],axis =1)\n",
    "#data_train.info 检验分离结果\n",
    "data_test = data_new[data_new.dteday>'2011/12/31']\n",
    "data_test = data_test.drop(['instant','dteday','season','mnth','yr','holiday','weekday','workingday','temp','casual','registered'],axis =1)\n",
    "#data_test.info 检验分离结果\n",
    "#data_train.head()\n",
    "\n",
    "X_train = data_train.drop('cnt',axis = 1)\n",
    "y_train = data_train['cnt'].values\n",
    "\n",
    "X_test = data_test.drop('cnt',axis = 1)\n",
    "y_test = data_test['cnt'].values\n",
    "columns = X_train.columns\n",
    "\n",
    "#X_test.isnull().sum()\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2.5数据预处理"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 125,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\validation.py:475: DataConversionWarning: Data with input dtype int64 was converted to float64 by MinMaxScaler.\n",
      "  warnings.warn(msg, DataConversionWarning)\n"
     ]
    }
   ],
   "source": [
    "#数据标准化\n",
    "#from sklearn.preprocessing import StandardScaler\n",
    "\n",
    "#生成标准化器\n",
    "#ss_X = StandardScaler()\n",
    "#ss_y = StandardScaler()\n",
    "\n",
    "#分别对训练和测试数据的特征以及目标值进行标准化处理 x= x- μ/σ\n",
    "#X_train = ss_X.fit_transform(X_train)\n",
    "#X_test = ss_X.fit_transform(X_test)\n",
    "\n",
    "#对y标准化按照例子是说，防止w差异太大，正则参数范围有限，y= wTx + λ|w| \n",
    "#y_train = ss_y.fit_transform(y_train.reshape(-1,1))\n",
    "#y_test = ss_y.transform(y_test.reshape(-1,1))\n",
    "#reshape(重构矩阵) (-1,1) 指不知道行数，根据原矩阵m*n / 1,得出新矩阵的 行数\n",
    "\n",
    "#数据归一化\n",
    "from sklearn.preprocessing import MinMaxScaler\n",
    "\n",
    "mm_X = MinMaxScaler()\n",
    "mm_y = MinMaxScaler()\n",
    "\n",
    "X_train = mm_X.fit_transform(X_train)\n",
    "X_test = mm_X.fit_transform(X_test)\n",
    "\n",
    "y_train = mm_y.fit_transform(y_train.reshape(-1,1))\n",
    "y_test = mm_y.fit_transform(y_test.reshape(-1,1))\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 3、确定模型类型"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3.1 先试下OLS"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 126,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>coef</th>\n",
       "      <th>columns</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>[0.63227766867597]</td>\n",
       "      <td>atemp</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>[0.09279050421752882]</td>\n",
       "      <td>season4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>[0.04115743867775504]</td>\n",
       "      <td>season2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>[0.019384287542492218]</td>\n",
       "      <td>weekday7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>[0.019187807528832923]</td>\n",
       "      <td>season3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>[0.018922053648288334]</td>\n",
       "      <td>holiday1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>[0.014254489023235]</td>\n",
       "      <td>weekday6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>[0.00668444085050935]</td>\n",
       "      <td>workingday2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>[-0.0004938047600887147]</td>\n",
       "      <td>weekday3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>[-0.003629224408039319]</td>\n",
       "      <td>weekday5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>[-0.006684440850509274]</td>\n",
       "      <td>workingday1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>[-0.007146674744713144]</td>\n",
       "      <td>weekday1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>[-0.008670768690535971]</td>\n",
       "      <td>weekday2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>[-0.013698303962349986]</td>\n",
       "      <td>weekday4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>[-0.018922053648287834]</td>\n",
       "      <td>holiday2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>[-0.1441994333345302]</td>\n",
       "      <td>hum</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>[-0.15313575042411676]</td>\n",
       "      <td>season1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>[-0.18585127014438305]</td>\n",
       "      <td>weathersit</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>[-0.19607580005068212]</td>\n",
       "      <td>windspeed</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                        coef      columns\n",
       "1         [0.63227766867597]        atemp\n",
       "9      [0.09279050421752882]      season4\n",
       "7      [0.04115743867775504]      season2\n",
       "16    [0.019384287542492218]     weekday7\n",
       "8     [0.019187807528832923]      season3\n",
       "4     [0.018922053648288334]     holiday1\n",
       "15       [0.014254489023235]     weekday6\n",
       "18     [0.00668444085050935]  workingday2\n",
       "12  [-0.0004938047600887147]     weekday3\n",
       "14   [-0.003629224408039319]     weekday5\n",
       "17   [-0.006684440850509274]  workingday1\n",
       "10   [-0.007146674744713144]     weekday1\n",
       "11   [-0.008670768690535971]     weekday2\n",
       "13   [-0.013698303962349986]     weekday4\n",
       "5    [-0.018922053648287834]     holiday2\n",
       "2      [-0.1441994333345302]          hum\n",
       "6     [-0.15313575042411676]      season1\n",
       "0     [-0.18585127014438305]   weathersit\n",
       "3     [-0.19607580005068212]    windspeed"
      ]
     },
     "execution_count": 126,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.linear_model import LinearRegression\n",
    "\n",
    "#使用默认配置初始化\n",
    "lr = LinearRegression()\n",
    "\n",
    "#训练模型参数\n",
    "lr.fit(X_train, y_train)\n",
    "\n",
    "#使用训练好的模型进行预测 输出值\n",
    "y_test_pred_lr = lr.predict(X_test)\n",
    "y_train_pred_lr = lr.predict(X_train)\n",
    "\n",
    "#查看各特征的\n",
    "fs = pd.DataFrame({\"columns\":list(columns),\"coef\":list((lr.coef_.T))})\n",
    "fs.sort_values(by=['coef'],ascending=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3.1.1模型评价"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 127,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The r2 score of LinearRegression on test is 0.5353597636585818\n",
      "The r2 score of LinearRegression on train is 0.7875191315721773\n"
     ]
    }
   ],
   "source": [
    "#使用r2_score评价模型\n",
    "#测试集\n",
    "print ('The r2 score of LinearRegression on test is',r2_score(y_test,y_test_pred_lr))\n",
    "\n",
    "#训练集\n",
    "print ('The r2 score of LinearRegression on train is',r2_score(y_train,y_train_pred_lr))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## r2评分为负值，可能是 按照2011年数据训练出来的 权重矩阵*2012年的特征 得出的预测值 与 实际的2012年的y 相差太大，然后预测值得方差 与实际方差 比值大于 1 ，然后导致了负值，不知道理解的对不对，希望老师指点下"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 128,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAekAAAFsCAYAAADos0H8AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAAHj5JREFUeJzt3XmUnHWd7/H3l6RJGAJh60AgxAQElbWDTSCDQDQqaJDguY7osITDEgWZi+sooEOLOqMD4tVLhmPcAAHZRoXrMhcngghXYRKMEYyaKDAmxBCiLGFNwvf+UU9iJ+lOV3dXd//S/X6dU6eqnvX7q+ruT/+e56lfRWYiSZLKs81AFyBJkjpmSEuSVChDWpKkQhnSkiQVypCWJKlQhrQkSYUypDXkRcRDETF1oOsYSBHx9oj4Y0SsjohJ/bjf1RGxTyfzzoiIexq0n0ci4o2N2JbUnwxpDWod/XHe9I9/Zh6YmXd1sZ0JEZERMbyPSh1olwPnZ+aozPzFpjOrtj9bheqyiLgiIob1dqfV/v7Q2+1Ig5UhLRWggPB/BfBQF8scmpmjgGOBk4Ez+7wqaYgzpDXkte9tR8TkiJgXEU9HxIqIuKJa7O7q/smqNzklIraJiI9HxKMR8XhEXBsRo9tt9/Rq3qqI+MQm+2mLiFsj4rqIeBo4o9r3zyLiyYhYHhFXRsS27baXEXFeRCyOiGci4lMRsW+1ztMRcXP75TdpY4e1RsSIiFgNDAN+GRG/7+r1yswlwL1AS7vtj46Ir1V1L4uIT6/vaUfEKyPiJxHxVEQ8ERE3bdKmV1aPd42I26u23A/s2265zY5kRMRdEXF29XjfiPhx9Vo/ERHXR8ROnbwWnb3HUnEMaWljXwS+mJk7UguJm6vpx1T3O1WHaH8GnFHdXg/sA4wCrgSIiAOAfwNOAcYCo4G9NtnXDOBWYCfgemAd8AFgN2AKMA04b5N1jgdeCxwJ/CMwp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jbbrtts9qWL1/OMcccQ0tLCwcddBA//elP62rTXXfdxQknnABAW1sbZ555JlOnTmWfffbZqHd93XXXMXnyZFpaWnjPe97DunXrADj33HNpbW3lwAMP3PAaQG3I60svvZTXve513HLLLXXVUq9+HbtbklS+devWMXfuXM466ywA7rjjDhYvXsz9999PZnLiiSdy9913s3LlSvbcc0++//3vA/DUU09ttJ3ly5dzySWXMH/+fEaPHs3rX/96Jk3a7MDsRkaOHMl3vvMddtxxR5544gmOPPJITjzxxI0uwLrhhhs47rjjuPjii1m3bh3PPfdcj9r5m9/8hjvvvJNnnnmGV73qVZx77rksWbKEm266iXvvvZempibOO+88rr/+ek4//XQ+85nPsMsuu7Bu3TqmTZvGwoULOeSQQzbUfc899/Soji0xpCVJADz//PO0tLTwyCOP8NrXvpY3velNQC2k77jjjg0Bu3r1ahYvXszRRx/Nhz/8YT760Y9ywgkncPTRR2+0vfvuu4+pU6ey/pM9J598Mr/73e+2WENmctFFF3H33XezzTbbsGzZMlasWMEee+yxYZnDDz+cM888kzVr1nDSSSfR0tKzUamnT5/OiBEjGDFiBGPGjGHFihXMnTuX+fPnc/jhh294TcaMGQPAzTffzJw5c1i7di3Lly/n17/+9YaQPvnkk3tUQ1c83C1JAv56TvrRRx/lpZdeYvbs2UAtOC+88EIWLFjAggULWLJkCWeddRb7778/8+fP5+CDD+bCCy/k0ksv3WybnX0Eafjw4bz88ssbtv/SSy8BcP3117Ny5Urmz5/PggUL2H333Tf7nPExxxzD3XffzV577cVpp53Gtdde26P2jhgxYsPjYcOGsXbtWjKTmTNnbmjrb3/7W9ra2nj44Ye5/PLLmTt3LgsXLmT69Okb1bX99tv3qIau2JOW1LF6ry5u9FXIGnCjR4/mS1/6EjNmzODcc8/luOOO4xOf+ASnnHIKo0aNYtmyZTQ1NbF27Vp22WUXTj31VEaNGsXVV1+90XaOOOIILrjgAlatWsWOO+7ILbfcwqGHHgrUzuPOnz+fd77zndx2222sWbMGqB0yHzNmDE1NTdx55508+ujm3+j46K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5lrgaeAXfulup6pp01bo+626yzgh31aUe/V1aaIeF9E/J5aT/p/9lNtfa43w4IWIyL+E9ijg1kX17mJ84AfZOYfS/rnvwHtIjP/CBxSHeb+bkTcmpkrGlVjdzWiTdV2xgLfBGZm5oD2dBrVpoLVMwRwXcMEF2Rrq7dedbcrIk4FWoFj+7Si3qt3COrZwOyI+Hvg48DMvi6sPwyKkM7MN3Y2LyJWRMTYzFxe/WF/vIPFpgBHR8R5wChg24hYnZkD+h3ZDWhX+209FhEPAUdTOxw5IBrRpojYEfg+8PHM/HkflVq3Rr5PhapnCOD1yyyNiOHAaODP/VNejwzWYY3raldEvJHaP5HHtjslVqruvlc3Alf1aUX9aCgc7r6dv/5HNRO4bdMFMvOUzByfmROADwPXDnRA16HLdkXEuIjYrnq8M3AUA/8tZFtST5u2Bb5D7T26pR9r66ku27QVqGcI4PbtfAfw4yx7pKTBOqxxl+2KiEnAl4ETM3Nr+Kexnjbt1+7pdGBxP9bXtzJzUN+onRebS+1NmwvsUk1vBb7awfJnAFcOdN2NaBfwJmAh8MvqftZA192ANp0KrAEWtLu1DHTtvf35A34KrASep9ZzOG6ga9+kHW8Ffkft/P/F1bRLqf2hBxgJ3AIsAe4H9hnomhvQpsOr9+JZYBXw0EDX3KB2/Sewot3vz+0DXXMD2vRF4KGqPXcCBw50zY26OSyoJEmFGgqHuyVJ2ioZ0pIkFcqQliSpUIa0JEmFMqQlSSqUIS1JUqEMaUmSCvX/Ab0yZL4awCopAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x28e48f030f0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "f, ax = plt.subplots(figsize=(7, 5))\n",
    "f.tight_layout()\n",
    "ax.hist(y_train - y_train_pred_lr,bins=40,label='Residuals Linear', color='r',alpha=0.5)\n",
    "ax.set_title(\"Histogram of Residuals\")\n",
    "ax.legend(loc='best');"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 129,
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TE3tC3lcyuHT/RuFPBZiaxAuDHnsJ/A7Gu28oZ8pLff5Uux33FPWBmMcE2zg3SkiJ4tIEoEJpmU+Bn5X9kREsh06r4ljlmCM00YDHxHo1s4Lef13QPfgam/fADc6dF4Tx6yb2hjjGivBGGNcYwnGGOMaSzDGGNdYgjHGuMYSjDHGNZZgjDGusQRjjHHN/wfH/xPDqQu5JgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x28e49286f28>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure(figsize=(4, 3))\n",
    "plt.scatter(y_train, y_train_pred_lr)\n",
    "plt.plot([-1,1],[-1,1], '--k') #数据已经标准化，3倍标准差即可\n",
    "plt.axis('tight')\n",
    "plt.xlabel('True num')\n",
    "plt.ylabel('Predicted num')\n",
    "plt.tight_layout()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 130,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The value of default measurement of SGDRegressor on test is 0.5145368254115668\n",
      "The value of default measurement of SGDRegressor on train is 0.7867816385567331\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\validation.py:578: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
      "  y = column_or_1d(y, warn=True)\n"
     ]
    }
   ],
   "source": [
    "#线性模型，随机梯度下降优化模型参数\n",
    "#随机梯度下降一般在大数据集上应用\n",
    "from sklearn.linear_model import SGDRegressor\n",
    "\n",
    "#使用默认配置初始化\n",
    "sgdr = SGDRegressor(max_iter=1000)\n",
    "\n",
    "#训练：参数估计\n",
    "sgdr.fit(X_train,y_train)\n",
    "\n",
    "#预测\n",
    "#sgdr_y_predict = sgdr.predict(X_test)\n",
    "#sgdr.coef_\n",
    "print ('The value of default measurement of SGDRegressor on test is',sgdr.score(X_test,y_test))\n",
    "print ('The value of default measurement of SGDRegressor on train is',sgdr.score(X_train,y_train))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3.2 正则化的线性回归（L2正则 - 岭回归）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 131,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The r2 score of RidgeCV on test is: 0.5334424555657995\n",
      "The r2 score of RidgeCV on train is: 0.7874864609964068\n"
     ]
    }
   ],
   "source": [
    "#岭回归\n",
    "\n",
    "from sklearn.linear_model import RidgeCV\n",
    "\n",
    "#设置超参数（正则参数）范围，助教说此部分设置是猜的，卿教授说此值设置10的指数\n",
    "alphas = [0.01,0.1,1,10,100]\n",
    "#n_alphas = 20 \n",
    "#alphas = np.logspace(-5,2,n_alphas)\n",
    "\n",
    "#三步走，1、生成实例，2、训练，3、预测\n",
    "#生成一个RidgeCV实例\n",
    "ridge = RidgeCV(alphas=alphas,store_cv_values=True)\n",
    "\n",
    "#模型训练\n",
    "ridge.fit(X_train, y_train)\n",
    "\n",
    "#预测\n",
    "y_test_pred_ridge = ridge.predict(X_test)\n",
    "y_train_pred_ridge = ridge.predict(X_train)\n",
    "\n",
    "#评估，使用R2 评分，评价模型在测试集和训练集的性能\n",
    "print('The r2 score of RidgeCV on test is:',r2_score(y_test,y_test_pred_ridge))\n",
    "print('The r2 score of RidgeCV on train is:',r2_score(y_train,y_train_pred_ridge))\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 可视化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 132,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZIAAAEKCAYAAAA4t9PUAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBod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Qg0/tIdOHFpLGAn8GnBcR2yU9fGDZYWT3YdSQ/Gzik/+7f0qmj7OzyLQw7M2K75PkYJYqN22ZFWY+cJOk0uS+xaVkOldcSGbgpxJJx5EZbvWAlcC4ZHoAsAvYkcRd08J+Ssj0/gvw5WT7hzIQ2JhcEX2VzPC5B5xE5+j92bo5X5GYFeYZMvc/3iRzlfAXEbFJ0tPAFWQ+sN8lMzLdjmSdZ8kUlhcj4k1Jr5PpHbYWWNTCfnYBp0lammznpsPk9S/A05JuJNM7766sZZ9NcjBLlXv/NWsjSf0jMyreEDJXKRcnRaYvmQ/3i5N7K4Vsa2dE9G+nvOYDUyNie3tsz6wlviIxa7ufSxoE9Aa+FxGbACJij6Tvkhkb+72OTChpfvtHFxHrCL4iMTOzNvHNdjMzaxMXEjMzaxMXEjMzaxMXEjMzaxMXEjMzaxMXEjMza5P/HzTKHdJunlTPAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x28e48ed36a0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "alpha is: 0.1\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>coef_lr</th>\n",
       "      <th>coef_ridge</th>\n",
       "      <th>columns</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>[0.63227766867597]</td>\n",
       "      <td>[0.6216987183049949]</td>\n",
       "      <td>atemp</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>[0.09279050421752882]</td>\n",
       "      <td>[0.0919802379531065]</td>\n",
       "      <td>season4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>[0.04115743867775504]</td>\n",
       "      <td>[0.04161459424689884]</td>\n",
       "      <td>season2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>[0.019384287542492218]</td>\n",
       "      <td>[0.019231616913178762]</td>\n",
       "      <td>weekday7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>[0.019187807528832923]</td>\n",
       "      <td>[0.021799321666867044]</td>\n",
       "      <td>season3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>[0.018922053648288334]</td>\n",
       "      <td>[0.018776076679144715]</td>\n",
       "      <td>holiday1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>[0.014254489023235]</td>\n",
       "      <td>[0.014194876558471847]</td>\n",
       "      <td>weekday6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>[0.00668444085050935]</td>\n",
       "      <td>[0.006712555812166787]</td>\n",
       "      <td>workingday2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>[-0.0004938047600887147]</td>\n",
       "      <td>[-0.0003718476354488409]</td>\n",
       "      <td>weekday3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>[-0.003629224408039319]</td>\n",
       "      <td>[-0.003578976203020945]</td>\n",
       "      <td>weekday5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>[-0.006684440850509274]</td>\n",
       "      <td>[-0.0067125558121681195]</td>\n",
       "      <td>workingday1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>[-0.007146674744713144]</td>\n",
       "      <td>[-0.007168096046202166]</td>\n",
       "      <td>weekday1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>[-0.008670768690535971]</td>\n",
       "      <td>[-0.00861061379210426]</td>\n",
       "      <td>weekday2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>[-0.013698303962349986]</td>\n",
       "      <td>[-0.013696959794875063]</td>\n",
       "      <td>weekday4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>[-0.018922053648287834]</td>\n",
       "      <td>[-0.018776076679144715]</td>\n",
       "      <td>holiday2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>[-0.1441994333345302]</td>\n",
       "      <td>[-0.1391926434724844]</td>\n",
       "      <td>hum</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>[-0.15313575042411676]</td>\n",
       "      <td>[-0.15539415386686972]</td>\n",
       "      <td>season1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>[-0.18585127014438305]</td>\n",
       "      <td>[-0.18738573261364255]</td>\n",
       "      <td>weathersit</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>[-0.19607580005068212]</td>\n",
       "      <td>[-0.19331102459313154]</td>\n",
       "      <td>windspeed</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                     coef_lr                coef_ridge      columns\n",
       "1         [0.63227766867597]      [0.6216987183049949]        atemp\n",
       "9      [0.09279050421752882]      [0.0919802379531065]      season4\n",
       "7      [0.04115743867775504]     [0.04161459424689884]      season2\n",
       "16    [0.019384287542492218]    [0.019231616913178762]     weekday7\n",
       "8     [0.019187807528832923]    [0.021799321666867044]      season3\n",
       "4     [0.018922053648288334]    [0.018776076679144715]     holiday1\n",
       "15       [0.014254489023235]    [0.014194876558471847]     weekday6\n",
       "18     [0.00668444085050935]    [0.006712555812166787]  workingday2\n",
       "12  [-0.0004938047600887147]  [-0.0003718476354488409]     weekday3\n",
       "14   [-0.003629224408039319]   [-0.003578976203020945]     weekday5\n",
       "17   [-0.006684440850509274]  [-0.0067125558121681195]  workingday1\n",
       "10   [-0.007146674744713144]   [-0.007168096046202166]     weekday1\n",
       "11   [-0.008670768690535971]    [-0.00861061379210426]     weekday2\n",
       "13   [-0.013698303962349986]   [-0.013696959794875063]     weekday4\n",
       "5    [-0.018922053648287834]   [-0.018776076679144715]     holiday2\n",
       "2      [-0.1441994333345302]     [-0.1391926434724844]          hum\n",
       "6     [-0.15313575042411676]    [-0.15539415386686972]      season1\n",
       "0     [-0.18585127014438305]    [-0.18738573261364255]   weathersit\n",
       "3     [-0.19607580005068212]    [-0.19331102459313154]    windspeed"
      ]
     },
     "execution_count": 132,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mse_mean = np.mean(ridge.cv_values_,axis =0)\n",
    "plt.plot(np.log10(alphas),mse_mean.reshape(len(alphas),1))\n",
    "\n",
    "#这是为了标出最佳参数的位置，不是必须\n",
    "#plt.plot(np.log10(ridge.alpha_)*np.ones(3), [0.28, 0.29, 0.30])\n",
    "\n",
    "plt.xlabel('log(alpha)')\n",
    "plt.ylabel('mse')\n",
    "plt.show()\n",
    "\n",
    "print('alpha is:',ridge.alpha_)\n",
    "\n",
    "# 看看各特征的权重系数，系数的绝对值大小可视为该特征的重要性\n",
    "fs = pd.DataFrame({\"columns\":list(columns),\"coef_lr\":list((lr.coef_.T)),\"coef_ridge\":list((ridge.coef_.T))})\n",
    "fs.sort_values(by=['coef_lr'],ascending=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3.3正则化的线性回归（L1正则 --> Lasso)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 133,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The r2 score of LassoCV on test is 0.4573232431418641\n",
      "The r2 score of LassoCV on train is 0.7763336936101106\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Anaconda3\\lib\\site-packages\\sklearn\\linear_model\\coordinate_descent.py:1094: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
      "  y = column_or_1d(y, warn=True)\n"
     ]
    }
   ],
   "source": [
    "#Lasso \n",
    "# class sklearn.linear_model.LassoCV(eps=0.001, n_alphas=100, alphas=None, fit_intercept=True, \n",
    "#                                    normalize=False, precompute=’auto’, max_iter=1000, \n",
    "#                                    tol=0.0001, copy_X=True, cv=None, verbose=False, n_jobs=1,\n",
    "#                                    positive=False, random_state=None, selection=’cyclic’)\n",
    "\n",
    "from sklearn.linear_model import LassoCV\n",
    "\n",
    "#设置超参数搜索范围\n",
    "#alphas = [ 0.01, 0.1, 1, 10,100] 加了性能不如不加的好\n",
    "\n",
    "#生成一个LassoCV实例\n",
    "#lasso = LassoCV(alphas = alphas)\n",
    "lasso = LassoCV()\n",
    "\n",
    "#训练\n",
    "lasso.fit(X_train,y_train)\n",
    "\n",
    "#测试\n",
    "y_test_pred_lasso = lasso.predict(X_test)\n",
    "y_train_pred_lasso = lasso.predict(X_train)\n",
    "\n",
    "#评估，使用r2_score评价模型\n",
    "print ('The r2 score of LassoCV on test is', r2_score(y_test,y_test_pred_lasso))\n",
    "print ('The r2 score of LassoCV on train is', r2_score(y_train,y_train_pred_lasso))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAEKCAYAAAD9xUlFAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW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/plain": [
       "<matplotlib.figure.Figure at 0x1630f39b6d8>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "alpha is: 0.01\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>coef_lasso</th>\n",
       "      <th>coef_lr</th>\n",
       "      <th>coef_ridge</th>\n",
       "      <th>columns</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>0.628957</td>\n",
       "      <td>[0.6362988757608581]</td>\n",
       "      <td>[0.6199997586609373]</td>\n",
       "      <td>atemp</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.287338</td>\n",
       "      <td>[0.2957029020958571]</td>\n",
       "      <td>[0.29309672303887097]</td>\n",
       "      <td>season</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.027206</td>\n",
       "      <td>[0.03662077786042608]</td>\n",
       "      <td>[0.035048526959316095]</td>\n",
       "      <td>weekday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[0.008164773997219738]</td>\n",
       "      <td>[0.008475839823330222]</td>\n",
       "      <td>workingday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>-0.023483</td>\n",
       "      <td>[-0.03100963108674718]</td>\n",
       "      <td>[-0.030518805549755612]</td>\n",
       "      <td>holiday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>-0.052077</td>\n",
       "      <td>[-0.06679313424393889]</td>\n",
       "      <td>[-0.06310401992355008]</td>\n",
       "      <td>hum</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>-0.101540</td>\n",
       "      <td>[-0.11222100128818825]</td>\n",
       "      <td>[-0.11138486852940271]</td>\n",
       "      <td>windspeed</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>-0.217609</td>\n",
       "      <td>[-0.2188330655395894]</td>\n",
       "      <td>[-0.21657899917213141]</td>\n",
       "      <td>weathersit</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   coef_lasso                 coef_lr               coef_ridge     columns\n",
       "5    0.628957    [0.6362988757608581]     [0.6199997586609373]       atemp\n",
       "0    0.287338    [0.2957029020958571]    [0.29309672303887097]      season\n",
       "2    0.027206   [0.03662077786042608]   [0.035048526959316095]     weekday\n",
       "3    0.000000  [0.008164773997219738]   [0.008475839823330222]  workingday\n",
       "1   -0.023483  [-0.03100963108674718]  [-0.030518805549755612]     holiday\n",
       "6   -0.052077  [-0.06679313424393889]   [-0.06310401992355008]         hum\n",
       "7   -0.101540  [-0.11222100128818825]   [-0.11138486852940271]   windspeed\n",
       "4   -0.217609   [-0.2188330655395894]   [-0.21657899917213141]  weathersit"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mses = np.mean(lasso.mse_path_, axis = 1)\n",
    "plt.plot(np.log10(lasso.alphas_), mses) \n",
    "#plt.plot(np.log10(lasso.alphas_)*np.ones(3), [0.3, 0.4, 1.0])\n",
    "plt.xlabel('log(alpha)')\n",
    "plt.ylabel('mses')\n",
    "plt.show()    \n",
    "            \n",
    "print ('alpha is:', lasso.alpha_)\n",
    "\n",
    "# 看看各特征的权重系数，系数的绝对值大小可视为该特征的重要性\n",
    "fs = pd.DataFrame({\"columns\":list(columns), \"coef_lr\":list((lr.coef_.T)), \"coef_ridge\":list((ridge.coef_.T)), \"coef_lasso\":list((lasso.coef_.T))})\n",
    "fs.sort_values(by=['coef_lr'],ascending=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
